package com.example.prom.ok.y2022.controller.email.common.Controller;

import com.example.prom.ok.y2022.controller.email.common.enums.CommonEmailEum;
import com.example.prom.ok.y2022.controller.email.common.model.OutputToExcelModel;
import com.example.prom.strategy.excel.CustomCellStyleStrategy;
import com.example.prom.strategy.excel.CustomColumnWidthStrategy;

import java.util.ArrayList;
import java.util.List;

import static com.alibaba.excel.EasyExcelFactory.write;

public class ExcelController {
    public static void main(String[] args) {

        List<OutputToExcelModel> outputToExcelList = new ArrayList<>();
        CommonEmailEum[] values = CommonEmailEum.values();
        for (CommonEmailEum value : values) {
            outputToExcelList.add(new OutputToExcelModel(value.getType(), value.getDesc(), null));
        }

        String fileName = "C:\\Users\\hp\\Desktop\\工作文件\\邮箱系统错误码说明.xlsx";
        write(fileName, OutputToExcelModel.class).sheet().head(OutputToExcelModel.class)
                .registerWriteHandler(new CustomColumnWidthStrategy())
                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(outputToExcelList);
        System.out.println("生成excel成功");
    }
}
